<?php !defined( 'SUNCMS' ) && exit( 'No direct script access allowed'  );

/**
 * 
 * Sun CMS
 * 
 * @author			Burning
 * @copyright		Copyright (c) 2009, IsunCms.Com.
 * @license			http://www.isuncms.com/license.htm
 * @link				http://www.isuncms.com/
 * @since				Version 1.0 Beta
 * 
 */

if( $do == 'index' )
{
	$tree = get_category( 'article' );
	$result = get_document_list();
	$articles = $result['documents'];
	$document_no = $result['documents_no'];
	$page_no = ceil( $document_no/15 );
	$page_no = $page_no == 0?1:$page_no;
	$page = 1;
	$first = 0;
	$prev = 0;
	$next = $page_no > 1?1:0;
	$last = $page_no > 1?$page_no:0;
	include( display( 'document_list' ) );
}
elseif( $do == 'getcategory' )
{
	$model = get_post( 'model' );cache_category($model);
	$tree = get_category( $model );
	echo json_encode( $tree );
}
elseif( $do == 'getlist' )
{
	$page = get_post( 'page' );
	$catid = get_post( 'catid' );
	$set = array
	(
		'stime' => trim( get_post( 'stime' ) ),
		'etime' => trim( get_post( 'etime' ) ),
		'keywords' => trim( get_post( 'keywords' ) ),
		'status' => get_post( 'status' ),
		'model' => get_post( 'model' )
	);
	$datas = get_document_list( $catid, ($page-1)*15, $set );
	$page_no = ceil( $datas['documents_no']/15 );
	$datas['page_no'] = $page_no == 0?1:$page_no;
	echo json_encode( $datas );
}
elseif( $do == 'new' )
{
	$cat = get_post( 'cat' );
	$time = date( 'Y-m-d H:i:s' );
	$model = get_post( 'model' );
	$model_info = get_model_info( $model );
	$from_list = $m_article->get_from_list();
	$author_list = $m_article->get_author_list();
	$province = $m_article->get_area( 'province' );
	include( display( $model.'_new' ) );
	unset( $cat, $time, $category, $from_list, $author_list, $province );
}